package org.raymond.iworks.study.netty.atguigu.netty.heatbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class HeatbeatServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if(evt instanceof IdleStateEvent idleStateEvent){
            String msg = "未超时";
            switch (idleStateEvent.state()){
                case READER_IDLE -> {
                    msg = "读空闲";
                }
                case WRITER_IDLE -> {
                    msg = "写空闲";
                }
                case ALL_IDLE -> {
                    msg = "读写空闲";
                }
            }
            log.warn("{} {}", ctx.channel().remoteAddress(), msg);
        }
    }
}
